﻿// <copyright file="BlockBoard.cs" company="Marcin Wosik">
// Copyright (c) 2010 All Right Reserved
// </copyright>
// <author>Marcin Wosik</author>
// <email>mawo11@gmail.com</email>
// <date>2010-02-25</date>
// <summary></summary>
namespace GameOfLife.GameData.Blocks
{
    using System;
    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;
    using System.Windows.Shapes;
    using GameOfLife.Interfaces;

    /// <summary>
    /// Board of block elements
    /// </summary>
    public class BlockBoard : BoardBase
    {
        #region Methods

        public override void Initialize(Canvas screen)
        {
            if (Data == null)
            {
                return;
            }

            base.Initialize(screen);

            // calculation width and height single block
            double blockWidth = screen.ActualWidth / Data.Columns;
            double blockHeight = screen.ActualHeight / Data.Rows;
            blockWidth = Math.Min(blockWidth, blockHeight);

            Data.Elements = new List<IElement>();

            double lastx = 0, lasty = 0;
            //TODO: musze dzisiaj tutaj opublikowac kod albo doprowadzic do dobrej jakosci i opublikowac
            // poniewaz to bedzie jedna z metod oceny mojej osoby ?
            for (int i = 0; i < Data.Rows; ++i)
            {
                // Data.Elements[i] = new BlockElement[Data.Columns];
                for (int c = 0; c < Data.Columns; ++c)
                {
                    // creating new elements
                    BlockElement tempElement = new BlockElement();

                    tempElement.PosX = i;
                    tempElement.PosY = c;
                    tempElement.ColoringMode = Data.ColoringMode;

                    Polygon newDrawer = new Polygon();
                    newDrawer.Points.Add(new Point(lastx, lasty));
                    newDrawer.Points.Add(new Point(lastx + blockWidth, lasty));
                    newDrawer.Points.Add(new Point(lastx + blockWidth, lasty + blockHeight));
                    newDrawer.Points.Add(new Point(lastx, lasty + blockHeight));

                    newDrawer.Stroke = new SolidColorBrush { Color = Colors.Black };
                    tempElement.Drawer = newDrawer;
                    Data.Elements.Add(tempElement);
                    screen.Children.Add(newDrawer);
                    lastx += blockWidth;
                }
                lasty += blockHeight;
                lastx = 0;
            }

            ((List<IElement>)Data.Elements).ForEach(t => t.MakeConnection(Data));
        }

        #endregion Methods
    }
}